﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;

namespace WebService1
{
    public class GetData
    {
        
        public static string GetGrade(string phone)
        {
            string kq="";
            bool flash=true;
            string sql = "select id from student where mobi=" + phone;
            DataTable id_student = Connect.Doc(sql);
            DataTable kqdiem = new DataTable();
            if (id_student.Rows.Count > 0)
            {
                sql = "";
                sql="select s.lastname,s.firstname, s.username,g.total,su.name,c.examdate,t.name as term,y.name as year from student s,grade g, course c,subject su,term t,year y where t.yearid=y.id and t.id=c.termid and s.id=g.studentid and g.courseid= c.id and c.subjectid=su.id and s.id=" +
                    id_student.Rows[0]["id"].ToString() + "group by su.name,s.lastname,s.firstname, s.username,g.total,c.examdate,t.name,y.name";
                kqdiem = Connect.Doc(sql);
                if (kqdiem.Rows.Count > 0)
                {
                    foreach (DataRow i in kqdiem.Rows)
                    {   
                        if(flash==false)
                            kq += " /n" + " Mon: " + i["name"] + " " + i["total"] + "điểm học kỳ " + i["term"] + " năm" + i["year"];
                        else
                            kq=i["lastname"]+" "+i["firstname"]+" mssv:"+i["username"]+ " Mon: "+i["name"]+" "+i["total"]+"điểm học kỳ "+i["term"]+" năm"+i["year"];
                    }
                }
                return kq;
            }
            else
                return kq;
        }

    }
}